'use strict'

let getServiceInfo = require ('./service/serviceInner');
let deployZookeeper = require ('./service/zookeeper');
let deployElasticsearch = require ('./service/elastisearch');
let deployKibana = require ('./service/kibana');
let deployKafka = require ('./service/kafka');
let deployAccesspoint = require ('./service/accesspoint');
let deployKong = require ('./service/kong');
let deployOrderHandle = require ('./service/orderhandle');
let depolySeckillManager = require ('./service/seckillmanager');
let deployTsungSlave = require ('./service/tsungslave');
let deployFluentd = require ('./service/fluentd');
let deployPostgres = require ('./service/postgres');
let deployMysql = require ('./service/mysql');
let generateConf = require ('./service/tsungMaster');


(async function () {
     const serviceInfo = await getServiceInfo();
     console.log(serviceInfo);
     generateConf(serviceInfo);
     await deployZookeeper(serviceInfo.zookeeper);
     await deployMysql(serviceInfo.mysql);
     await deployPostgres(serviceInfo.kong);
     await deployElasticsearch(serviceInfo.elasticsearch);
     await deployKibana(serviceInfo.kibana, serviceInfo.elasticsearch);
     await deployFluentd(serviceInfo.elasticsearch , serviceInfo.accesspoint,serviceInfo.kong);

     setTimeout(async function(){
         console.log("deploy");
         await deployKafka(serviceInfo.kafka , serviceInfo.zookeeper ,serviceInfo.tsungMaster);
         await deployAccesspoint(serviceInfo.accesspoint, serviceInfo.zookeeper,
             serviceInfo.redis,serviceInfo.elasticsearch,serviceInfo.tsungMaster);
         await deployKong(serviceInfo.kong , serviceInfo.zookeeper,serviceInfo.tsungMaster);
         await deployTsungSlave(serviceInfo.tsungSlave , serviceInfo.tsungMaster);
         await deployOrderHandle(serviceInfo.orderhandle , serviceInfo.zookeeper ,serviceInfo.mysql ,serviceInfo.redis);
         await depolySeckillManager(serviceInfo.seckillManager,serviceInfo.zookeeper,serviceInfo.redis,serviceInfo.kongRedis);

     },30000);



})();